// pages/account/charge.js

const app = getApp()
const { wxPost, wxGet, commonShare, serviceBusy } = require('../../../utils/common.js')

Page({
  data: {
    waitLoading:true,
    fundingLevel:true
  },
  onLoad: function (options) {
    this.setData({ infoId: options.infoId||''})
    var pages = getCurrentPages()
    var prevPage = pages[pages.length - 2] //上一个页面
    if (prevPage) {
      const { summary, updateDate, info}=prevPage.data
      this.setData({ updateDate: updateDate || '', summary: summary || '', info: info||''})
    }
    this.loadDetail()
  },
  loadDetail(){
    const { infoId } = this.data
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    wxGet(`/assetsInfo/chargeProfile`, { infoId},({data})=>{
        if(data && data['errorCode']===0){
          const { planningFundsProfile, fundingLevelProfile,planningFundsDetails, unPayList, payList}=data
          this.setData({
            planningFundsProfile: planningFundsProfile || '',
            fundingLevelProfile: fundingLevelProfile || '',
            planningFundsDetails: planningFundsDetails || '',
            unPayList: unPayList || '',
            payList: payList || ''
          })
        }
    },null,()=>{
      this.setData({
        waitLoading: false
      })
      wx.hideLoading()
    })
  },
  toogleShow: function (event) {
    const { key } = event.currentTarget.dataset
    this.setData({ [key]: !this.data[key] })
  },
  viewHistory:function(e){
    wx.navigateTo({
      url: `history?infoId=${this.data.infoId}`,
    })
  },
  viewPlanningFundRecords:function(){
    wx.navigateTo({
      url: `planningFundsRecords?infoId=${this.data.infoId}`,
    })
  },
  viewChargeDetail:function(e){
    const { id } = e.currentTarget.dataset
    wx.navigateTo({
      url: `detail?id=${id}&from=unPay`
    })
  }
})